package com.hp.ecs.sonar.util;

import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.After;

public abstract class BaseTestCase {
	protected Mockery context = new Mockery() {
		{
			setImposteriser(ClassImposteriser.INSTANCE);
		}
	};

	/**
	 * Create mock object with JMock. <br/>
	 * If the target object has a field matched with the mock object,<br/>
	 * then the mock object will be assigned to the field.
	 * 
	 * @param clazz
	 * @return
	 * 
	 * @since
	 */
	protected final <T> T mock(Class<T> clazz) {
		return this.context.mock(clazz, clazz.getName());
	}

	@After
	public void after() {
		this.context.assertIsSatisfied();
	}

	/**
	 * Use the method starting with "assert" for the sonar rule "JUnit tests should include an assert".
	 */
	protected final void assertMock(Expectations expectations) {
		this.context.checking(expectations);
	}
}
